package com.logansoft.zhxypkoa.domain.sys;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.springframework.context.annotation.Scope;

import com.logansoft.zhxypkoa.domain.Base;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 角色模型
 * 
 * @author zhuyj
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = "s_sys_role")
@Scope(value = "prototype")
public class Role extends Base {

  private static final long serialVersionUID = 1L;

  /**
   * 包含用户
   */
  @Column(name = "CODE", length = 128)
  private String code;
  @ManyToMany(mappedBy = "roles", fetch = FetchType.LAZY)
  private List<User> users;
  /**
   * 菜单组
   */
  @ManyToMany(fetch = FetchType.LAZY, targetEntity = Menu.class)
  @JoinTable(name = "s_sys_role_menu", joinColumns = {
      @JoinColumn(name = "ROLE_ID", referencedColumnName = "ID") }, inverseJoinColumns = {
          @JoinColumn(name = "MENU_ID", referencedColumnName = "ID") })
  private List<Menu> menus;
  @ManyToMany(fetch = FetchType.LAZY, targetEntity = Premission.class)
  @JoinTable(name = "s_sys_role_premission", joinColumns = {
      @JoinColumn(name = "ROLE_ID", referencedColumnName = "ID") }, inverseJoinColumns = {
          @JoinColumn(name = "PREMISSION_ID", referencedColumnName = "ID") })
  private List<Premission> premissions;
}
